﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bitirme.Controllers;
using Bitirme.DAL.Entities;
using Bitirme.DAL.Enum;

namespace Bitirme.Views
{
    public partial class ShowEmployee : System.Web.UI.Page
    {
        static List<ScheduleEventItem> events;
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            int employeeID = Int32.Parse(id);

            AssignmentHandler asHandler = new AssignmentHandler();
            EmployeeHandler emHandler = new EmployeeHandler();
            Employee employee = emHandler.GetEmployeeByID(employeeID);
            List<Assignment> assignedList = asHandler.GetAssignmentsByEmployeeID(employeeID);

            ScheduleEventItem tempEventItem;
            Project tempProject;
            ScheduleEventHandler scheduleEventHandler = new ScheduleEventHandler();

            events = new List<ScheduleEventItem>();
            EmployeeName.Text = employee.Name + " " + employee.SurName;
            EmployeeEmail.Text = employee.Email;
            foreach (KeyValuePair<Capability, SkillLevel> pair in employee.Skills)
            {
                if (EmployeeSkills.Text=="")
                    EmployeeSkills.Text += pair.Key.Name;
                else
                    EmployeeSkills.Text += ", " + pair.Key.Name;
            }

            foreach (Assignment assignedItem in assignedList) {

                tempEventItem = new ScheduleEventItem();
                tempProject = new Project();
                tempProject = asHandler.GetProjectByWorkPackageID(assignedItem.WorkPackage.ID);
                tempEventItem.EmployeeName = employee.Name;
                tempEventItem.WorkPackageName = assignedItem.WorkPackage.Name;
                tempEventItem.StartDate = assignedItem.StartDate.ToString();
                tempEventItem.EndDate = assignedItem.EndDate.ToString();
                tempEventItem.WorkPackageID = assignedItem.WorkPackage.ID;
                tempEventItem.Title = tempProject.Name + " - " + assignedItem.WorkPackage.Name;

                events.Add(tempEventItem);
            }
        }

        [System.Web.Services.WebMethod]
        public static List<ScheduleEventItem> GetEvents()
        {
            return events;
        }
    }
}